package org.ThreadDemo.pool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

public class ThreadPoolDemo1 {

    public static void main(String[] args) throws Exception {
        //一池N=5线程
//        int num = Runtime.getRuntime().availableProcessors();
//        System.out.println(num);
        //ExecutorService threadpool1 = Executors.newFixedThreadPool(num);
        //单一窗口
         //ExecutorService threadpool2 = Executors.newSingleThreadExecutor();


        ExecutorService threadpool2 = Executors.newCachedThreadPool();



        //10个顾客请求
        try{
            for(int i =0;i<=100;i++) {
                threadpool2.execute(
                        ()->{
                            System.out.println(Thread.currentThread().getName()+"办理业务");
                            try {
                                TimeUnit.SECONDS.sleep(3);
                            } catch (InterruptedException e) {
                                throw new RuntimeException(e);
                            }
                        }
                );

            }
        }catch(Exception e) {
            e.printStackTrace();
        }finally{
            threadpool2.shutdown();
        }

    }
}
